//
//  OrderDetialViewController.m
//  ForestPack
//
//  Created by 骆锴 on 2018/7/26.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OrderDetialViewController.h"
#import "FPCommodityHeaderView.h"
#import "InputViewCell.h"
#import "OrderDetialCell.h"
#import "PaperBoxListCell.h"
#import "ConfirmViewCell.h"
#import "AddressManageViewController.h"
#import "AddressManagerModel.h"
#import "SelectPayMethodsView.h"
#import "PaySuccessViewController.h"

@interface OrderDetialViewController ()<UITableViewDelegate,UITableViewDataSource,passValueDelegate>

@property (nonatomic, strong)AddressManageViewController *addressManageViewController;
@property (nonatomic, strong)AddressManagerDataModel *addressDataModel;
@property (nonatomic, strong)BaseTableView *tableView;
@property (nonatomic, strong)SelectPayMethodsView *selectPayMethodView;
@property (nonatomic, assign) BOOL isPaper;
@property (nonatomic, assign) BOOL isCompany;
@property (nonatomic, assign) BOOL isJifen;
@property (nonatomic, assign) BOOL isCoupons;
@property (nonatomic, strong) UIButton *personBtn;
@property (nonatomic, strong) UIButton *companyBtn;
@property (nonatomic, strong) UIButton *eleBtn1;
@property (nonatomic, strong) UIButton *eleBtn2;
@property (nonatomic, strong) UIButton *paperBtn1;
@property (nonatomic, strong) UIButton *paperBtn2;
@property (nonatomic, strong) UIButton *noBillBtn;
@property (nonatomic, strong) UIButton *isUseJiFeng;
@property (nonatomic, strong) NSString *integral;
@property (nonatomic, strong) NSString *useIntegral;
@property (nonatomic, strong) NSString *cutPrice;
@property (nonatomic, strong) NSString *balance;
@property (nonatomic, strong) NSString *orderId;
//订单内容

@property (nonatomic, assign) NSInteger             invoice_type;
@property (nonatomic, strong) UITextField           *invoice_title;
@property (nonatomic, strong) UITextField           *invoice_shuiwuhao;
@property (nonatomic, strong) UITextField           *invoice_content;
@property (nonatomic, strong) NSString              *remark1;
//@property (nonatomic, strong) NSMutableString       *remark2;
@property (nonatomic, strong) NSString              *couponsid;
@property (nonatomic, strong) NSString              *consjifen;
@property (nonatomic, assign) NSInteger             wuliu_type;
@property (nonatomic, strong) NSString              *design_pic;
@property (nonatomic, strong) NSString              *express_fee;
@property (nonatomic, strong) NSMutableString       *realPrice;

@end

@implementation OrderDetialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _addressManageViewController = [[AddressManageViewController alloc] init];
    _addressManageViewController.delegate = self;
    _addressManageViewController.tableView.allowsSelection = YES;
    _addressManageViewController.isSelect = YES;
    _isPaperBoard = YES;
    _isPackaging = NO;
    _isPaper = NO;
    _isCompany = NO;
    _invoice_type = 1;
    _wuliu_type = 1;
    _isJifen = NO;
    _isCoupons = NO;
    if (_isPaperBoard == YES) {
         _realPrice = [[NSString stringWithFormat:@"%.2f",[_total_price floatValue] + 50.00] mutableCopy];
    }
    [self setTitle:@"提交订单"];
    [self setfooter];
    [self setSelectPayMethodsView];
    [self setTableView];
    [self getIntegral];
    [self requestData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setSelectPayMethodsView{
    self.selectPayMethodView = [[SelectPayMethodsView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    __weak __typeof(self) weakSelf = self;
    self.selectPayMethodView.hiddenClick = ^{
        [weakSelf hiddenSelectPayMethodsView];
    };
    self.selectPayMethodView.doneClick = ^{
        [weakSelf getBalance];
    };
    [kKeyWindow addSubview:self.selectPayMethodView];
}

- (void)hiddenSelectPayMethodsView{
    self.selectPayMethodView.shadowBtn.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.selectPayMethodView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
    }];
}

- (void)setTableView {
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49)) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2){
        return 5;
    }else if (section == 5){
        if (_isPaperBoard == YES) {
            return 6;
        }else{
            return 7;
        }
    }
    else{
        return 1;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return ScreenX375(94);
    }else if (indexPath.section == 1){
        return ScreenX375(127);
    }else if (indexPath.section == 2){
        if (!_isCompany && indexPath.section == 2 && indexPath.row == 3) {
            return 0;
        } else
        if (indexPath.row == 0) {
            return ScreenX375(134);
        }
            return ScreenX375(46);
    }else if(indexPath.section == 3){
        return ScreenX375(168.5);
    }else if(indexPath.section == 4){
        return ScreenX375(125.5);
    }else{
        if (_isPaperBoard == YES) {
            return ScreenX375(42);
        }else{
            if (indexPath.row == 7) {
                return ScreenX375(49);
            }else{
                return ScreenX375(42);
            }
        }
    }
}

-(void)setfooter{
    UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(0),SCREEN_HEIGHT - ScreenX375(49) - NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, ScreenX375(49))];
    
    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
    title.text = @"合计：";
    title.font = Kfont(13);
    title.textColor = REXADECIMALCOLOR(@"#333333");
    title.textAlignment = NSTextAlignmentLeft;
    [baseView addSubview:title];
    
    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(50.5), ScreenX375(15), ScreenX375(150), ScreenX375(13))];
    value.text = [NSString stringWithFormat:@"%@元",_realPrice];
    value.font = Kfont(13);
    value.textColor = ThemeColor;
    value.textAlignment = NSTextAlignmentRight;
    [baseView addSubview:value];
    
    UIButton *order =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(257.5), ScreenX375(0), ScreenX375(117.5), ScreenX375(49))];
    order.backgroundColor = ThemeColor;
    [order setTitle:@"下单" forState:UIControlStateNormal];
    order.titleLabel.font = Kfont(14);
    order.titleLabel.textColor = [UIColor whiteColor];
    [order setBackgroundColor:ThemeColor];
    [order addTarget:self action:@selector(pay) forControlEvents:UIControlEventTouchUpInside];
    [baseView addSubview:order];
    
    [self.view addSubview:baseView];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        OrderDetialCell *cell = [OrderDetialCell cellWithTableView:tableView andIndexPath:indexPath];
        if (_addressDataModel) {
            [cell initWithModel:_addressDataModel];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 1){
        ExpressMethodCell *cell = [ExpressMethodCell cellWithTableView:tableView andIndexPath:indexPath];
        __weak typeof (cell) weakCell = cell;
        cell.selectClick = ^{
            if (weakCell.specialcar.isSelected == NO) {
                weakCell.specialcar.selected = YES;
                weakCell.specialcar.layer.borderColor = ThemeColor.CGColor;
                weakCell.express.selected = NO;
                weakCell.express.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
                self.wuliu_type = 1;
            }else{
                weakCell.specialcar.selected = NO;
                weakCell.specialcar.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
                weakCell.express.selected = YES;
                weakCell.express.layer.borderColor = ThemeColor.CGColor;
                self.wuliu_type = 2;
            }
        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 2){
        if (indexPath.row == 0) {
            static NSString *cellId = @"classCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(80), ScreenX375(46))];
                noteLabel.text = @"发票类型";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                self.eleBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(32), ScreenX375(160), ScreenX375(34))];
                self.eleBtn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.eleBtn1 setTitle:@"  电子发票-增值普票" forState:UIControlStateNormal];
                [self.eleBtn1 setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.eleBtn1.titleLabel.font = Kfont(12);
                [self.eleBtn1 setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.eleBtn1 setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.eleBtn1.selected = YES;
                [self.eleBtn1 addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.eleBtn1];
                
                self.paperBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(169), ScreenX375(32), ScreenX375(160), ScreenX375(34))];
                self.paperBtn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.paperBtn1 setTitle:@"  纸质发票-增值普票" forState:UIControlStateNormal];
                [self.paperBtn1 setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.paperBtn1.titleLabel.font = Kfont(12);
                [self.paperBtn1 setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.paperBtn1 setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.paperBtn1.selected = NO;
                [self.paperBtn1 addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.paperBtn1];
                
                self.eleBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(66), ScreenX375(160), ScreenX375(34))];
                self.eleBtn2.titleLabel.textAlignment = NSTextAlignmentLeft;
                self.eleBtn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.eleBtn2 setTitle:@"  电子发票-增值专票" forState:UIControlStateNormal];
                [self.eleBtn2 setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.eleBtn2.titleLabel.font = Kfont(12);
                [self.eleBtn2 setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.eleBtn2 setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.eleBtn2.selected = NO;
                [self.eleBtn2 addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.eleBtn2];
                
                self.paperBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(169), ScreenX375(66), ScreenX375(160), ScreenX375(34))];
                self.paperBtn2.titleLabel.textAlignment = NSTextAlignmentLeft;
                self.paperBtn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.paperBtn2 setTitle:@"  纸质发票-增值专票" forState:UIControlStateNormal];
                [self.paperBtn2 setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.paperBtn2.titleLabel.font = Kfont(12);
                [self.paperBtn2 setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.paperBtn2 setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.paperBtn2.selected = NO;
                [self.paperBtn2 addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.paperBtn2];
                
                self.noBillBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(100), ScreenX375(160), ScreenX375(34))];
                self.noBillBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
                self.noBillBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                [self.noBillBtn setTitle:@"  不使用发票" forState:UIControlStateNormal];
                [self.noBillBtn setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.noBillBtn.titleLabel.font = Kfont(12);
                [self.noBillBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.noBillBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.noBillBtn.selected = NO;
                [self.noBillBtn addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.noBillBtn];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(134) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else if (indexPath.row == 1) {
            static NSString *cellId = @"classCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(80), ScreenX375(46))];
                noteLabel.text = @"抬头类型：";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                self.personBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(77), ScreenX375(6), ScreenX375(113), ScreenX375(34))];
                [self.personBtn setTitle:@"  个人" forState:UIControlStateNormal];
                [self.personBtn setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.personBtn.titleLabel.font = Kfont(16);
                [self.personBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.personBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.personBtn.selected = YES;
                self.personBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
                self.personBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
                [self.personBtn addTarget:self action:@selector(selectClass:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.personBtn];
                
                self.companyBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(199), ScreenX375(6), ScreenX375(113), ScreenX375(34))];
                [self.companyBtn setTitle:@"  企业" forState:UIControlStateNormal];
                [self.companyBtn setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                self.companyBtn.titleLabel.font = Kfont(16);
                [self.companyBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                [self.companyBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                self.companyBtn.selected = NO;
                self.companyBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
                self.companyBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
                [self.companyBtn addTarget:self action:@selector(selectClass:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:self.companyBtn];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(46) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else if (indexPath.row == 2){
            static NSString *cellId = @"titleCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(80), ScreenX375(46))];
                noteLabel.text = @"发票抬头：";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
                UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
                NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
                [bar setItems:buttonsArray];
                
                _invoice_title = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(86), 0, SCREEN_WIDTH - ScreenX375(110), ScreenX375(46))];
                _invoice_title.placeholder = @"填写发票抬头";
                _invoice_title.font = Kfont(14);
                _invoice_title.inputAccessoryView = bar;
                [cell addSubview:_invoice_title];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(46) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else if (indexPath.row == 3){
            static NSString *cellId = @"numberCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            for (UIView *subView in cell.subviews) {
                [subView removeFromSuperview];
            }
            if (_isCompany) {
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(80), ScreenX375(46))];
                noteLabel.text = @"税       号：";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
                UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
                NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
                [bar setItems:buttonsArray];
                
                _invoice_shuiwuhao = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(86), 0, SCREEN_WIDTH - ScreenX375(110), ScreenX375(46))];
                _invoice_shuiwuhao.placeholder = @"填写纳税人识别号";
                _invoice_shuiwuhao.font = Kfont(14);
                _invoice_shuiwuhao.inputAccessoryView = bar;
                [cell addSubview:_invoice_shuiwuhao];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(46) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            static NSString *cellId = @"contentCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), 0, ScreenX375(80), ScreenX375(46))];
                noteLabel.text = @"发票内容：";
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
                UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
                NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
                [bar setItems:buttonsArray];
                
                _invoice_content = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(86), 0, SCREEN_WIDTH - ScreenX375(110), ScreenX375(46))];
                _invoice_content.placeholder = @"选择发票内容";
                _invoice_content.font = Kfont(14);
                _invoice_content.inputAccessoryView = bar;
                [cell addSubview:_invoice_content];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(46) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }else if(indexPath.section == 3){
        OtherCell *cell = [OtherCell cellWithTableView:tableView andIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        __weak typeof (self) weakSelf = self;
        cell.block = ^(NSString *text){
            weakSelf.remark2 = [text mutableCopy];
        };
         __weak typeof (cell) weakCell = cell;
        cell.isCouponsClick = ^{
            if (weakCell.Nocoupon.isSelected == NO) {
                weakCell.Nocoupon.selected = YES;
                self.isCoupons = YES;
            }else{
                weakCell.Nocoupon.selected = NO;
                self.isCoupons = NO;
            }
        };
        return cell;
    }else if(indexPath.section == 4){
        ProductInformationCell *cell = [ProductInformationCell cellWithTableView:tableView andIndexPath:indexPath];
        if (_deialData) {
            [cell initWithArray:_deialData];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        if (_isPaperBoard == NO) {
            if (indexPath.row == 0) {
                static NSString *cellId = @"designCell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UIImageView *select = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(20), ScreenX375(5), ScreenX375(5))];
                    select.image = [UIImage imageNamed:@"选择"];
                    [cell addSubview: select];
                    
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(28.5), ScreenX375(15), ScreenX375(60), ScreenX375(13))];
                    title.text = @"定制设计";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = @"￥50";
                    value.font = Kfont(13);
                    value.textColor = ThemeColor;
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                return cell;
            }else if(indexPath.row == 1){
                static NSString *cellId = @"vipCell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                    title.text = @"会员等级优惠";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = @"0.00";
                    value.font = Kfont(13);
                    value.textColor = REXADECIMALCOLOR(@"#333333");
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 2){
                static NSString *cellId = @"jifenCell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    NSString *integral = [[NSString alloc] init];
                    NSString *priceValue = [[NSString alloc] init];
                    
                    if ([self.integral floatValue] / 100 < [self.total_price floatValue]) {
                        integral = [NSString stringWithFormat:@"可使用%@的积分抵扣",self.integral];
                        priceValue = [NSString stringWithFormat:@"-%.2f元",[self.integral floatValue] / 100];
                        self.cutPrice = [NSString stringWithFormat:@"%.2f",[self.integral floatValue] / 100];
                        self.useIntegral = self.integral;
                    }else{
                        integral = [NSString stringWithFormat:@"可使用%.0f的积分抵扣",[self.total_price floatValue]*100];
                        priceValue = [NSString stringWithFormat:@"-%@元",self.total_price];
                        self.cutPrice = [NSString stringWithFormat:@"%@",self.total_price];
                        self.useIntegral = [NSString stringWithFormat:@"%f",[self.total_price floatValue] * 100];
                    }
                    
                    self.isUseJiFeng = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(14), ScreenX375(160), ScreenX375(14))];
                    self.isUseJiFeng.titleLabel.textAlignment = NSTextAlignmentLeft;
                    self.isUseJiFeng.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                    
                    [self.isUseJiFeng setTitle:integral forState:UIControlStateNormal];
                    [self.isUseJiFeng setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                    self.isUseJiFeng.titleLabel.font = Kfont(12);
                    [self.isUseJiFeng setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                    [self.isUseJiFeng setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                    self.isUseJiFeng.selected = NO;
                    [self.isUseJiFeng addTarget:self action:@selector(jifeng) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:self.isUseJiFeng];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = priceValue;
                    value.font = Kfont(13);
                    value.textColor = REXADECIMALCOLOR(@"#333333");
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 3){
                static NSString *cellId = @"addresscell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                title.text = @"配送至";
                title.font = Kfont(13);
                title.textColor = REXADECIMALCOLOR(@"#333333");
                title.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:title];
                
                UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(16.5), ScreenX375(262), ScreenX375(13))];
                value.text = [NSString stringWithFormat:@"%@%@%@",_addressDataModel.province,_addressDataModel.city,_addressDataModel.district];
                value.font = Kfont(13);
                value.textColor = REXADECIMALCOLOR(@"#333333");
                value.textAlignment = NSTextAlignmentRight;
                [cell addSubview:value];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
                
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 4){
                static NSString *cellId = @"Consigneecell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                title.text = @"收货人";
                title.font = Kfont(13);
                title.textColor = REXADECIMALCOLOR(@"#333333");
                title.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:title];
                
                UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                value.text = [NSString stringWithFormat:@"%@  %@",_addressDataModel.consignee,_addressDataModel.telephone];
                value.font = Kfont(13);
                value.textColor = REXADECIMALCOLOR(@"#333333");
                value.textAlignment = NSTextAlignmentRight;
                [cell addSubview:value];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
            else if(indexPath.row == 5){
                static NSString *cellId = @"productnumcell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                    title.text = @"商品数量";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = [NSString stringWithFormat:@"%@个",_goods_nums];
                    value.font = Kfont(13);
                    value.textColor = REXADECIMALCOLOR(@"#333333");
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 6){
                static NSString *cellId = @"pricecell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(212), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                    title.text = @"优惠后金额：";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(290), ScreenX375(15), ScreenX375(72), ScreenX375(13))];
                    value.text = [NSString stringWithFormat:@"%.2f元",[_total_price floatValue] - [_cutPrice floatValue]];
                    value.font = Kfont(13);
                    value.textColor = ThemeColor;
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.backgroundColor = REXADECIMALCOLOR(@"#dcdcdc");
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
            else{
                static NSString *cellId = @"totalcell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                    title.text = @"合计：";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(50.5), ScreenX375(15), ScreenX375(150), ScreenX375(13))];
                    value.text = [NSString stringWithFormat:@"%.2f元",[_total_price floatValue] - [_cutPrice floatValue]];
                    value.font = Kfont(13);
                    value.textColor = ThemeColor;
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIButton *order =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(257.5), ScreenX375(0), ScreenX375(117.5), ScreenX375(49))];
                    order.backgroundColor = ThemeColor;
                    [order setTitle:@"下单" forState:UIControlStateNormal];
                    order.titleLabel.font = Kfont(14);
                    order.titleLabel.textColor = [UIColor whiteColor];
                    [order setBackgroundColor:ThemeColor];
                    [order addTarget:self action:@selector(getBalance) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:order];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
        }else{
            if (indexPath.row == 0) {
                static NSString *cellId = @"vipCell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                    title.text = @"会员等级优惠";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = @"0.00";
                    value.font = Kfont(13);
                    value.textColor = REXADECIMALCOLOR(@"#333333");
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 1){
                static NSString *cellId = @"jifenCell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    NSString *integral = [[NSString alloc] init];
                    NSString *priceValue = [[NSString alloc] init];
                    
                    if ([self.integral floatValue] / 100 < [self.total_price floatValue]) {
                        integral = [NSString stringWithFormat:@"可使用%@的积分抵扣",self.integral];
                        priceValue = [NSString stringWithFormat:@"-%.2f元",[self.integral floatValue] / 100];
                        self.cutPrice = [NSString stringWithFormat:@"%.2f",[self.integral floatValue] / 100];
                        self.useIntegral = self.integral;
                    }else{
                        integral = [NSString stringWithFormat:@"可使用%.0f的积分抵扣",[self.total_price floatValue]*100];
                        priceValue = [NSString stringWithFormat:@"-%@元",self.total_price];
                        self.cutPrice = [NSString stringWithFormat:@"%@",self.total_price];
                        self.useIntegral = [NSString stringWithFormat:@"%f",[self.total_price floatValue] * 100];
                    }
                    
                    self.isUseJiFeng = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(14), ScreenX375(160), ScreenX375(14))];
                    self.isUseJiFeng.titleLabel.textAlignment = NSTextAlignmentLeft;
                    self.isUseJiFeng.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                    
                    [self.isUseJiFeng setTitle:integral forState:UIControlStateNormal];
                    [self.isUseJiFeng setTitleColor:REXADECIMALCOLOR(@"#333333") forState:UIControlStateNormal];
                    self.isUseJiFeng.titleLabel.font = Kfont(12);
                    [self.isUseJiFeng setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
                    [self.isUseJiFeng setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
                    self.isUseJiFeng.selected = NO;
                    [self.isUseJiFeng addTarget:self action:@selector(jifeng) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:self.isUseJiFeng];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = priceValue;
                    value.font = Kfont(13);
                    value.textColor = REXADECIMALCOLOR(@"#333333");
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 2){
                static NSString *cellId = @"addresscell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                title.text = @"配送至";
                title.font = Kfont(13);
                title.textColor = REXADECIMALCOLOR(@"#333333");
                title.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:title];
                
                UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(16.5), ScreenX375(262), ScreenX375(13))];
                value.text = [NSString stringWithFormat:@"%@%@%@",_addressDataModel.province,_addressDataModel.city,_addressDataModel.district];
                value.font = Kfont(13);
                value.textColor = REXADECIMALCOLOR(@"#333333");
                value.textAlignment = NSTextAlignmentRight;
                [cell addSubview:value];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
                
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else if(indexPath.row == 3){
                static NSString *cellId = @"Consigneecell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                title.text = @"收货人";
                title.font = Kfont(13);
                title.textColor = REXADECIMALCOLOR(@"#333333");
                title.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:title];
                
                UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                value.text = [NSString stringWithFormat:@"%@  %@",_addressDataModel.consignee,_addressDataModel.telephone];
                value.font = Kfont(13);
                value.textColor = REXADECIMALCOLOR(@"#333333");
                value.textAlignment = NSTextAlignmentRight;
                [cell addSubview:value];
                
                UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.image = [UIImage imageNamed:@"虚线"];
                [cell addSubview:line];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                return cell;
            }
            else if(indexPath.row == 4){
                static NSString *cellId = @"productnumcell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    
                    UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                    title.text = @"商品数量";
                    title.font = Kfont(13);
                    title.textColor = REXADECIMALCOLOR(@"#333333");
                    title.textAlignment = NSTextAlignmentLeft;
                    [cell addSubview:title];
                    
                    UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(180), ScreenX375(16.5), ScreenX375(182), ScreenX375(13))];
                    value.text = [NSString stringWithFormat:@"%@个",_goods_nums];
                    value.font = Kfont(13);
                    value.textColor = REXADECIMALCOLOR(@"#333333");
                    value.textAlignment = NSTextAlignmentRight;
                    [cell addSubview:value];
                    
                    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                    line.image = [UIImage imageNamed:@"虚线"];
                    [cell addSubview:line];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }else{
                static NSString *cellId = @"pricecell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UILabel *title =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(212), ScreenX375(15), ScreenX375(80), ScreenX375(13))];
                title.text = @"优惠后金额：";
                title.font = Kfont(13);
                title.textColor = REXADECIMALCOLOR(@"#333333");
                title.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:title];
                
                UILabel *value =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(290), ScreenX375(15), ScreenX375(72), ScreenX375(13))];
                value.text = [NSString stringWithFormat:@"%@元",_realPrice];
                value.font = Kfont(13);
                value.textColor = ThemeColor;
                value.textAlignment = NSTextAlignmentRight;
                [cell addSubview:value];
                
                UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(42), SCREEN_WIDTH - ScreenX375(26), 0.5)];
                line.backgroundColor = REXADECIMALCOLOR(@"#dcdcdc");
                [cell addSubview:line];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section < 5) {
        return ScreenX375(54);
    }
        return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section < 5) {
        return ScreenX375(10);
    }
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        OrderFirstSectionHeaderView * sectionView = [OrderFirstSectionHeaderView sectionHeaderViewWithHeight:54];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else if (section == 1){
        OrderSecondSectionHeaderView * sectionView = [OrderSecondSectionHeaderView sectionHeaderViewWithHeight:54];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else if (section == 2){
        OrderThirdSectionHeaderView * sectionView = [OrderThirdSectionHeaderView sectionHeaderViewWithHeight:54];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else if(section == 3){
        OrderFourthSectionHeaderView * sectionView = [OrderFourthSectionHeaderView sectionHeaderViewWithHeight:54];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else if(section == 4){
        OrderFifthSectionHeaderView * sectionView = [OrderFifthSectionHeaderView sectionHeaderViewWithHeight:54];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else{
        return nil;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        [self.navigationController pushViewController:_addressManageViewController animated:YES];
    }
}

- (void)selectClass:(UIButton *)button {
    if (button == _personBtn) {
        _personBtn.selected = YES;
        _companyBtn.selected = NO;
        _isCompany = NO;
    }else {
        _personBtn.selected = NO;
        _companyBtn.selected = YES;
        _isCompany = YES;
    }
    [_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:3 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
}

- (void)selectType:(UIButton *)button {
    if (button == _eleBtn1) {
        _eleBtn1.selected = YES;
        _eleBtn2.selected = NO;
        _paperBtn1.selected = NO;
        _paperBtn2.selected = NO;
        _noBillBtn.selected = NO;
        _invoice_type = 1;
    }else if(button == _paperBtn1)
    {
        _eleBtn1.selected = NO;
        _eleBtn2.selected = NO;
        _paperBtn1.selected = YES;
        _paperBtn2.selected = NO;
        _noBillBtn.selected = NO;
        _invoice_type = 2;
    }else if(button == _paperBtn2){
        _eleBtn1.selected = NO;
        _eleBtn2.selected = NO;
        _paperBtn1.selected = NO;
        _paperBtn2.selected = YES;
        _noBillBtn.selected = NO;
        _invoice_type = 3;
    }else if(button == _eleBtn2){
        _eleBtn1.selected = NO;
        _eleBtn2.selected = YES;
        _paperBtn1.selected = NO;
        _paperBtn2.selected = NO;
        _noBillBtn.selected = NO;
        _invoice_type = 4;
    }else {
        _eleBtn1.selected = NO;
        _eleBtn2.selected = NO;
        _paperBtn1.selected = NO;
        _paperBtn2.selected = NO;
        _noBillBtn.selected = YES;
        _invoice_type = 0;
    }
}

-(void)jifeng{
    if (_isUseJiFeng.selected == NO) {
        _isUseJiFeng.selected = YES;
        _isJifen = YES;
        _realPrice = [[NSString stringWithFormat:@"%.2f",[_total_price floatValue] - [_cutPrice floatValue] + 50.00] mutableCopy];
        [self.tableView reloadData];
    }else{
        _isUseJiFeng.selected = NO;
        _isJifen = NO;
        _realPrice = [[NSString stringWithFormat:@"%.2f",[_total_price floatValue] + 50.00] mutableCopy];
        [self.tableView reloadData];
    }
}

-(void)pay{
    if(_isCompany){
        if (_invoice_title.text.length == 0 && _invoice_type !=  0) {
            [HttpManager showNoteMsg:@"请填写发票抬头"];
        }else if (_invoice_shuiwuhao.text.length == 0 && _invoice_type !=  0){
            [HttpManager showNoteMsg:@"请填写发票税号"];
        }else if (_invoice_content.text.length == 0 && _invoice_type !=  0){
            [HttpManager showNoteMsg:@"请填写发票内容"];
        }else{
            self.selectPayMethodView.price.text = [NSString stringWithFormat:@"¥ %@",_realPrice];
            [UIView animateWithDuration:0.3 animations:^{
                self.selectPayMethodView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.selectPayMethodView.shadowBtn.alpha = 1;
            }];
        }
    }else{
        if (_invoice_title.text.length == 0 && _invoice_type !=  0) {
            [HttpManager showNoteMsg:@"请填写发票抬头"];
        }else if (_invoice_content.text.length == 0 && _invoice_type !=  0){
            [HttpManager showNoteMsg:@"请填写发票内容"];
        }else{
            self.selectPayMethodView.price.text = [NSString stringWithFormat:@"¥ %@",_realPrice];
            [UIView animateWithDuration:0.3 animations:^{
                self.selectPayMethodView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.selectPayMethodView.shadowBtn.alpha = 1;
            }];
        }
    }
}

-(void)passValue:(AddressManagerDataModel *)model{
    _addressDataModel = model;
    [self.tableView reloadData];
}

-(void)requestData{
    NSString * url = [NSString stringWithFormat:@"%@app/address_info",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"page":@"1"};
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [self.tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            for(NSDictionary *dict in successResponse[@"data"][@"data"]){
                AddressManagerDataModel *model = [[AddressManagerDataModel alloc] initWithDictionary:dict error:&error];
                if ([model.Default isEqualToString:@"1"]) {
                    self.addressDataModel = model;
                }
            }
            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [self.tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

-(void)getIntegral{
    NSString * url = [NSString stringWithFormat:@"%@app/total_integral",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":[FPLoginAndRegisterTools getToken]};
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            self.integral = successResponse[@"integral"];
            [self.tableView reloadData];
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [self.tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

-(void)getBalance{
    NSString * url = [NSString stringWithFormat:@"%@app/wallet_balance",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token")};
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            self.balance = successResponse[@"balance"];
            if ([self.balance floatValue] > [self.realPrice floatValue]) {
                [self sentOrder];
            }else{
                [HttpManager showNoteMsg:@"余额不足"];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [self.tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

-(void)pay_by_wallet{
    NSString * url = [NSString stringWithFormat:@"%@app/order_pay_by_wallet",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"order_id":_orderId,@"password":@"123456"};
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            [HttpManager showNoteMsg:@"支付成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.selectPayMethodView removeFromSuperview];
                PaySuccessViewController *vc = [[PaySuccessViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            });
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [self.tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

-(void)sentOrder{
    if (_isPaperBoard == NO && _isPackaging == NO) {
        if (_invoice_title.text.length == 0 && _invoice_type !=  0) {
            [HttpManager showNoteMsg:@"请输入发票抬头"];
        }else if (_invoice_content.text.length == 0 && _invoice_type !=  0){
            [HttpManager showNoteMsg:@"请输入发票内容"];
        }else{
            NSString * url = [NSString stringWithFormat:@"%@app/create_carton_order",REQUESTHEADER];
            NSDictionary * parameter1 = @{@"token":kNSUDefaultReadKey(@"token"),@"address_id":self.addressDataModel.Id,@"shop_id":_shop_id,@"admin_id":_admin_id,@"factory":kNSUDefaultReadKey(@"FactoryId"),@"goods_id":_goods_id,@"wuliu_type":[NSNumber numberWithInteger:_wuliu_type],@"goods_nums":_goods_nums,@"total_price":[NSString stringWithFormat:@"%.2f",[_total_price floatValue]-[_cutPrice floatValue]],@"express_fee":@"50"};
            
            NSMutableDictionary *parameter2 = [[NSMutableDictionary alloc] initWithDictionary:parameter1];
            
            if(_isCompany){
                [parameter2 setValue:_invoice_shuiwuhao.text forKey:@"invoice_shuiwuhao"];
            }
            if (_isCoupons){
                [parameter2 setValue:_couponsid forKey:@"couponsid"];
            }
            if (_isJifen) {
                [parameter2 setValue:_integral forKey:@"consjifen"];
            }
            if (_remark2 != nil) {
                [parameter2 setValue:_remark2 forKey:@"remark2"];
            }
            if (_logo != nil) {
                [parameter2 setValue:_logo forKey:@"design_pic"];
            }
            if (_invoice_type != 0) {
                [parameter2 setValue:[NSNumber numberWithInteger:_invoice_type] forKey:@"invoice_type"];
                [parameter2 setValue:_invoice_title.text forKey:@"invoice_title"];
                [parameter2 setValue:_invoice_content.text forKey:@"invoice_content"];
            }
            [HttpManager postHttpRequestByPost:url andParameter:parameter2 success:^(id successResponse) {
                [HttpManager hideWait];
                [self.tableView.mj_header endRefreshing];
                NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
                if ([status isEqualToString:@"1"]) {
                    self.orderId = successResponse[@"order_id"];
                    [self pay_by_wallet];
                }else{
                    [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
                }
            } andFailure:^(id failureResponse) {
                [self.tableView.mj_header endRefreshing];
                [HttpManager showFail];
            }];
        }
    }else if(_isPaperBoard == YES && _isPackaging == NO){
        if (_invoice_title.text.length == 0 && _invoice_type !=  0) {
            [HttpManager showNoteMsg:@"请输入发票抬头"];
        }else if (_invoice_content.text.length == 0 && _invoice_type !=  0){
            [HttpManager showNoteMsg:@"请输入发票内容"];
        }else{
            NSString * url = [NSString stringWithFormat:@"%@app/create_cardboard_order",REQUESTHEADER];
            NSDictionary * parameter1 = @{@"token":kNSUDefaultReadKey(@"token"),@"address_id":self.addressDataModel.Id,@"factory":kNSUDefaultReadKey(@"FactoryId"),@"goods_id":_goods_id,@"wuliu_type":[NSNumber numberWithInteger:_wuliu_type],@"goods_nums":_goods_nums,@"total_price":[NSString stringWithFormat:@"%.2f",[_total_price floatValue]-[_cutPrice floatValue]],@"express_fee":@"50"};
            
            NSMutableDictionary *parameter2 = [[NSMutableDictionary alloc] initWithDictionary:parameter1];
            if(_isCompany){
                [parameter2 setValue:_invoice_shuiwuhao.text forKey:@"invoice_shuiwuhao"];
            }
            if (_isCoupons){
                [parameter2 setValue:_couponsid forKey:@"couponsid"];
            }
            if (_isJifen) {
                [parameter2 setValue:_integral forKey:@"consjifen"];
            }
            if (_invoice_type != 0) {
                [parameter2 setValue:[NSNumber numberWithInteger:_invoice_type] forKey:@"invoice_type"];
                [parameter2 setValue:_invoice_title.text forKey:@"invoice_title"];
                [parameter2 setValue:_invoice_content.text forKey:@"invoice_content"];
            }
            [HttpManager postHttpRequestByPost:url andParameter:parameter2 success:^(id successResponse) {
                [HttpManager hideWait];
                [self.tableView.mj_header endRefreshing];
                NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
                if ([status isEqualToString:@"1"]) {
                    self.orderId = successResponse[@"order_id"];
                    [self pay_by_wallet];
                }else{
                    [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
                }
            } andFailure:^(id failureResponse) {
                [self.tableView.mj_header endRefreshing];
                [HttpManager showFail];
            }];
        }
    }else{
        if (_invoice_title.text.length == 0 && _invoice_type !=  0) {
            [HttpManager showNoteMsg:@"请输入发票抬头"];
        }else if (_invoice_content.text.length == 0 && _invoice_type !=  0){
            [HttpManager showNoteMsg:@"请输入发票内容"];
        }else{
            NSString * url = [NSString stringWithFormat:@"%@app/create_package_order",REQUESTHEADER];
            NSDictionary * parameter1 = @{@"token":kNSUDefaultReadKey(@"token"),@"address_id":self.addressDataModel.Id,@"shop_id":_shop_id,@"admin_id":_admin_id,@"factory":kNSUDefaultReadKey(@"FactoryId"),@"goods_id":_goods_id,@"wuliu_type":[NSNumber numberWithInteger:_wuliu_type],@"goods_nums":_goods_nums,@"total_price":[NSString stringWithFormat:@"%.2f",[_total_price floatValue]-[_cutPrice floatValue]],@"express_fee":@"50"};
            
            NSMutableDictionary *parameter2 = [[NSMutableDictionary alloc] initWithDictionary:parameter1];
            
            if(_isCompany){
                [parameter2 setValue:_invoice_shuiwuhao.text forKey:@"invoice_shuiwuhao"];
            }
            if (_isCoupons){
                [parameter2 setValue:_couponsid forKey:@"couponsid"];
            }
            if (_isJifen) {
                [parameter2 setValue:_integral forKey:@"consjifen"];
            }
            if (_remark2 != nil) {
                [parameter2 setValue:_remark2 forKey:@"remark2"];
            }
            if (_invoice_type != 0) {
                [parameter2 setValue:[NSNumber numberWithInteger:_invoice_type] forKey:@"invoice_type"];
                [parameter2 setValue:_invoice_title.text forKey:@"invoice_title"];
                [parameter2 setValue:_invoice_content.text forKey:@"invoice_content"];
            }
            [HttpManager postHttpRequestByPost:url andParameter:parameter2 success:^(id successResponse) {
                [HttpManager hideWait];
                [self.tableView.mj_header endRefreshing];
                NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
                if ([status isEqualToString:@"1"]) {
                    self.orderId = successResponse[@"order_id"];
                    [self pay_by_wallet];
                }else{
                    [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
                }
            } andFailure:^(id failureResponse) {
                [self.tableView.mj_header endRefreshing];
                [HttpManager showFail];
            }];
        }
    }
}

-(void)resignKey{
    [_invoice_title resignFirstResponder];
    [_invoice_content resignFirstResponder];
    [_invoice_shuiwuhao resignFirstResponder];
}

@end
